<template>
  <div>
    <Authc permissions="auth:thirdApplication:edit">
      <Tooltip placement="top" content="编辑">
        <Icon class="normal-icon-style" type="ios-create" @click="handleEdit" />
      </Tooltip>
    </Authc>
    <Authc permissions="auth:thirdApplication:delete">
      <Tooltip content="删除" placement="top">
        <Icon class="error-icon-style" type="ios-trash" @click="handleDelete" />
      </Tooltip>
    </Authc>
  </div>
</template>
<script>
import { Icon, Tooltip, Message, Modal } from "view-design";
import Authc from "@/components/Authc";
import { namespace } from "../../module";

export default {
  props: {
    row: Object
  },
  components: {
    Icon,
    Tooltip,
    Message,
    Authc
  },
  data: function() {
    return {};
  },
  methods: {
    handleEdit() {
      let id = this.row.id;
      this.$router.push("edit/" + id);
    },
    handleDelete() {
      let row = this.$props.row;
      let id = row.id;
      let store = this.$store;
      Modal.confirm({
        title: "确定删除",
        content: "删除后无法恢复",
        okText: "确定",
        cancelText: "取消",
        onOk: async () => {
          let responst = await store.dispatch(`${namespace}/delete`, {
            id: id
          });
          if (responst instanceof Object && responst.errorcode === 0) {
            Message.success("删除成功");
            store.dispatch(`${namespace}/query`);
          } else {
            Message.error("删除失败");
          }
        }
      });
    }
  }
};
</script>
<style lang="less">
.normal-icon-style {
  font-size: 20px !important;
  color: #57a3f3 !important;
}
.error-icon-style {
  font-size: 20px !important;
  color: #ff0000 !important;
}
</style>